# backend/app.py
from flask import Flask
from flask_cors import CORS
from flask_mysqldb import MySQL
import os
from dotenv import load_dotenv
from auth_routes import auth_bp, init_auth
# 初始化Flask应用
app = Flask(__name__)
CORS(app, supports_credentials=True)

# 加载配置
load_dotenv()
app.secret_key = os.getenv('SECRET_KEY', 'default-secret-key')
app.config['MYSQL_HOST'] = os.getenv('MYSQL_HOST', 'localhost')
app.config['MYSQL_USER'] = os.getenv('MYSQL_USER', 'root')
app.config['MYSQL_PASSWORD'] = os.getenv('MYSQL_PASSWORD', '23')
app.config['MYSQL_DB'] = os.getenv('MYSQL_DB', 'sxf')

# 初始化MySQL
mysql = MySQL(app)
init_auth(mysql)

# 注册蓝图
from auth_routes import auth_bp
from essay_rater import rater_bp
from writing_assistant import guide_bp

app.register_blueprint(auth_bp, url_prefix='/api')
app.register_blueprint(rater_bp, url_prefix='/api')
app.register_blueprint(guide_bp, url_prefix='/api')


if __name__ == '__main__':
    app.run(port=5000, debug=True)